package com.neuedu.web;

import com.neuedu.service.ArticleService;
import com.neuedu.service.ArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ArticleShowServlet",urlPatterns = "/article/show")
public class ArticleShowServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取查看文章的id
        String aid = request.getParameter("artid");
        // 调service
        ArticleService articleService = new ArticleServiceImpl();
        // 获取文章内容
        Map<String,Object> articleDetail = articleService.getArticleDetail(Long.parseLong(aid));
        // 获取评论
        List<Map<String,Object>> commList = articleService.getCommList(Long.parseLong(aid));
        // 本周热议
        request.setAttribute("articleDetail",articleDetail);
        request.setAttribute("commList",commList);
        // 转发到detail
        request.getRequestDispatcher("/WEB-INF/jsp/jie/detail.jsp").forward(request,response);
    }
}
